#ifndef INPUT_STERAM
#define INPUT_STERAM

class OutputStream {
	public:
		OutputStream() { reset(); } 

		bool write(int ch) { 
			if (_index < sizeof(_buffer))
				_buffer[_index++] = (char)ch;
			else {
			    fprintf(stderr, "Buffer full!\n");
				return false;
			}				
			return true;
		}

		const char *getStr() const { return _buffer; }
		void  reset() { _index = 0; memset(_buffer, 0, sizeof(_buffer));}

	private:
		int  _index;
		char _buffer[1024];
};



class InputStream {
public:
	InputStream() : _fp(NULL) {}
	~InputStream() { close(); }

	bool open(const char *file) {
	    close();
		_fp = fopen(file, "r");
		return _fp != NULL;
	}

	void close() {
	    if (_fp) {
	        fclose(_fp);
	        _fp = NULL;
	    }
    }
            
	int getc() { 
		if (_fp == NULL) 
			return -1;
		return ::getc(_fp); 
	}

	void ungetc(int ch) { if (_fp) ::ungetc(ch, _fp); }
	
    int eof() {
        return feof(_fp);
    }
        
private:
	FILE *_fp;
};




#endif
